package com.alibaba.otter.manager.biz.config.alarm.dal;

import com.alibaba.otter.manager.biz.config.alarm.dal.dataobject.AlarmRuleDO;
import com.alibaba.otter.manager.biz.config.alarm.dto.AlarmRuleQueryDTO;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRuleStatus;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * AlarmRuleDao: 数据操作接口
 * <p>
 * 这只是一个减少手工创建的模板文件
 * 可以任意添加方法和实现, 更改作者和重定义类名
 * <p/>@author Powered By Fluent Mybatis
 */
public interface AlarmRuleDao extends BaseMapper<AlarmRuleDO> {

    List<AlarmRuleDO> listByStatus( @Param("status") AlarmRuleStatus alarmRuleStatus);

    List<AlarmRuleDO> listByPipelineId(@Param("pipelineId") Long pipelineId);

    List<AlarmRuleDO> listByPipelineIdAndAlarmRuleStatus(@Param("pipelineId")Long pipelineId, @Param("status")AlarmRuleStatus status);

    default Page<AlarmRuleDO> pageByQuery(AlarmRuleQueryDTO query, Pageable pageable){
        QueryWrapper q = QueryWrapper.create()
                .eq(AlarmRuleDO::getPipelineId, query.getPipelineId(), Objects::nonNull)
                .orderBy(AlarmRuleDO::getPipelineId,true);
        return paginate(pageable.getPageNumber(), pageable.getPageSize(), q);
    }

    int getCount();

}
